﻿using UnityEngine;
using System.Collections;

namespace Game.UI
{
    /// <summary>
    /// 游戏中的主要画布，用于游戏play时的主界面服务；
    /// </summary>
    /// <remarks>挂载在主Canvas上即可实现单例获取</remarks>
	public class MainGameCanvas : MonoBehaviour 
	{
        //如果有指定UIContainer，则此将作为Canvas的RectTransform，否则Canvas根为Canvas
        [SerializeField] RectTransform m_mainGameCanvas;

        //--额外的画布：用于提供世界坐标下的Canvas，不一定有
        [SerializeField] RectTransform m_gameWorldCanvas;

        /// <summary>
        /// 取游戏主画布，一般用于游戏UI主面板
        /// </summary>
        public static RectTransform UIMainGameCanvas{get;private set;}

        /// <summary>
        /// 额外的画布：用于提供世界坐标下的Canvas，不一定有
        /// </summary>
        public static RectTransform UIGameWorldCanvas{get;private set;}
        
        [System.Obsolete("Use UIMainGameCanvas") ]
        /// <summary>
        /// 取游戏主画布，一般用于游戏UI主面板
        /// </summary>
        internal static RectTransform canvasRectTransform
        {
            get
            {
                #if UNITY_EDITOR
                if (UIMainGameCanvas == null)
                {
                    Debug.LogError("NO GAME CAVAS ASSIGNED IN CURRENT SCENE!");
                }
                #endif

                return UIMainGameCanvas;
            }
        }

		void Awake () 
		{
            //如果有指定画布的Container，则使用之。否则默认悬挂的物体就是Canvas：
            if (m_mainGameCanvas == null)
            {
                UIMainGameCanvas = this.GetComponent<RectTransform>();
            }
            else
            {
                UIMainGameCanvas = m_mainGameCanvas;
            }

            //世界坐标的：
            if(m_gameWorldCanvas!=null)
            {
                UIGameWorldCanvas = m_gameWorldCanvas;
            }
		}

	}
}